﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;

namespace QLTV_GiaoDien
{
    public partial class frm_TaiLieu_NhaXuatBan : DevExpress.XtraEditors.XtraForm
    {
        public frm_TaiLieu_NhaXuatBan()
        {
            InitializeComponent();
        }
        public void load_NXB(int ma)
        {
            txt_Load.Text = ma.ToString();
        }
        private void frm_TaiLieu_NhaXuatBan_Load(object sender, EventArgs e)
        {
            gridControl1.DataSource = nhaXuatBan_bll.LayDuLieu();
            txt_Load.Hide();
        }
        private void btn_Add_Click(object sender, EventArgs e)
        {
            frm_TaiLieu_NhaXuatBan_Them f = new frm_TaiLieu_NhaXuatBan_Them();
            f.Flag = 0;
            f.MyGetData = new frm_TaiLieu_NhaXuatBan_Them.GetInt(load_NXB);
            f.ShowDialog();
        }

        private void btn_Edit_Click(object sender, EventArgs e)
        {
            frm_TaiLieu_NhaXuatBan_Them f = new frm_TaiLieu_NhaXuatBan_Them();
            f.Flag = 1;
            f.MyGetData = new frm_TaiLieu_NhaXuatBan_Them.GetInt(load_NXB);
            f.MaNhaXuatBan=Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Nhà Xuất Bản").ToString());
            f.TenNhaXuatBan = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            f.DiaChi = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Địa Chỉ").ToString();
            f.SoDienThoai = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Số Điện Thoại").ToString();
            f.Fax= gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Fax").ToString();
            f.Email = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Email").ToString();
            f.GhiChu = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Ghi Chú").ToString();
            f.ShowDialog();
        }
        NhaXuatBan_BLL nhaXuatBan_bll = new NhaXuatBan_BLL();

        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        NhatKy_Public nk = new NhatKy_Public();
        TrungGian tg = new TrungGian();
        private void btn_Xoa_Click(object sender, EventArgs e)
        {
            NhaXuatBan_Public nxb = new NhaXuatBan_Public();
            nxb.MaNhaXuatBan =Convert.ToInt32( gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Nhà Xuất Bản").ToString());
            nxb.TenNhaXuatBan = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Tên Nhà Xuất Bản").ToString();
            if (XtraMessageBox.Show("Bạn có muốn xóa nhà xuất bản:" + nxb.TenNhaXuatBan + " có mã số là:" + nxb.MaNhaXuatBan + " này không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                nhaXuatBan_bll.delete_nhaXuatBan(nxb);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Xóa";
                nk.MoTa = "Xóa thông tin Nhà xuất bản: '" +nxb.TenNhaXuatBan + "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
            }
            frm_TaiLieu_NhaXuatBan_Load(sender,e);
        }

        private void btn_Thoat_Click(object sender, EventArgs e)
        {
            //this.Dispose();
            this.Close();
        }
        public delegate void GetInt(int kiemTra);
        public GetInt MyData;
        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            MyData(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"Mã Nhà Xuất Bản")));
            this.Close();
        }

        private void btn_Chon_Click(object sender, EventArgs e)
        {
            MyData(Convert.ToInt32(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Mã Nhà Xuất Bản")));
            this.Close();
        }

        private void txt_Load_TextChanged(object sender, EventArgs e)
        {
            if (txt_Load.Text == "1")
            {
                frm_TaiLieu_NhaXuatBan_Load(sender, e);
                txt_Load.Text="0";
            }
        }

    }
}